package com.vcg.retry.test;

import lombok.extern.java.Log;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by wuyu on 2016/9/16.
 */
@Service
@Log
public class RetryService {

    AtomicInteger increament = new AtomicInteger(0);

    @Retryable(value = RuntimeException.class)
    public void retry() {
        int i = increament.incrementAndGet();
        log.info("重试" + i);

        throw new RuntimeException("抛出异常");

    }

    @Recover
    public void recover1(RuntimeException e) {
        System.out.println(e.getMessage());
        System.out.println("do recover operation1");
    }

}
